package com.zhixuan.autoui.sample;

import android.os.Bundle;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.tinker.coresdk.manager.ZXAirConditionManager;
import com.zhixuan.autoui.R;

import cd.zhixuan.utils.recycler.RecyclerGridSelectTextView;
import cd.zhixuan.utils.recycler.adapter.BaseRecyclerAdapter;
import cd.zhixuan.utils.recycler.adapter.RecyclerListAdapter;
import cd.zhixuan.utils.recycler.adapter.listener.OnBindHolder;
import cd.zhixuan.utils.recycler.adapter.listener.OnItemClickListener;

/**
 * @author HuZhiChao
 * Create Time: 2022.01.04
 **/
public class AirConditionActivity extends BaseTestActivity {
    private RecyclerGridSelectTextView<String> rgstView;

    @Override
    protected int onContentLayout() {
        return R.layout.sample_activity_air_condition;
    }

    @Override
    protected void onCreated(Bundle savedInstanceState) {
        rgstView = findViewById(R.id.rgst_view);
        RecyclerListAdapter<String> adapter = rgstView.getAdapter();
        adapter.setChoiceState(BaseRecyclerAdapter.ChoiceState.NONE);
        adapter.setChoiceMode(BaseRecyclerAdapter.ChoiceMode.NONE);
        adapter.bindHolder(new OnBindHolder<RecyclerView.ViewHolder, String>() {
            @Override
            public void onBind(RecyclerView.ViewHolder viewHolder, String s, int i) {
                TextView text = viewHolder.itemView.findViewById(R.id.text);
                text.setText(s);
            }
        });
        adapter.setOnItemClickListener(new OnItemClickListener<RecyclerView.ViewHolder, String>() {


            @Override
            public boolean onItemClick(RecyclerView.ViewHolder viewHolder, String s, int i) {
                switch (s) {
                    case "设置温度":
                        requestSetTemperature();
                        break;
                }
                return true;
            }
        });
        adapter.setDataList(new String[]{"设置温度"});

    }

    private final float[] TEMPERATURE = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    private int tempIndex = 0;

    private void requestSetTemperature() {
        final int index = tempIndex++ % TEMPERATURE.length;
        float v = TEMPERATURE[index];
        try {
            ZXAirConditionManager.getInstance().requestSetTemperature(v);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
